package com.twl.app.base.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.twl.app.base.util.BeanFactoryHolder;
import com.twl.facade.web.PeripheralService;

public class PeripheralServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5927792303001960303L;

	private static PeripheralService peripheralServiceImpl = PeripheralService.class.cast(BeanFactoryHolder.getBean("peripheralServiceImpl"));

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String result = null;
		try {
			if (PeripheralFunction.GET_BANK_ACCOUNT.getFunction().equals(request.getParameter("function"))) {
				result = peripheralServiceImpl.getBankAccount(request.getParameter("empno"));
			} else {
				result = "{\"success\":"+false+",\"errmsg\":\"找不到该方法\"}";
			}
		} catch (Exception e) {
			result = "{\"success\":"+false+",\"errmsg\":\"发生未知错误\"}";
			e.printStackTrace();
		}

		//针对post请求，设置允许接收中文
		request.setCharacterEncoding("UTF-8");
		//设置可以在页面中响应的内容类型及中文
		response.setContentType("text/html;charset=UTF-8");
		//得到响应流对象
		PrintWriter out = response.getWriter();

		out.write(result);

		out.flush();
		out.close();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

}
